#pragma once

#include <base.h>

#define MSR_GS_BASE 0xc0000101
#define MSR_KERN_GS_BASE 0xc0000102

void mmio_write8(uintptr_t base, ptrdiff_t byte_off, uint8_t val);
void mmio_write16(uintptr_t base, ptrdiff_t byte_off, uint16_t val);
void mmio_write32(uintptr_t base, ptrdiff_t byte_off, uint32_t val);
void mmio_write64(uintptr_t base, ptrdiff_t byte_off, uint64_t val);

uint8_t mmio_read8(uintptr_t base, ptrdiff_t byte_off);
uint16_t mmio_read16(uintptr_t base, ptrdiff_t byte_off);
uint32_t mmio_read32(uintptr_t base, ptrdiff_t byte_off);
uint64_t mmio_read64(uintptr_t base, ptrdiff_t byte_off);

void io_write8(uint16_t port, uint8_t val);
void io_write16(uint16_t port, uint16_t val);
void io_write32(uint16_t port, uint32_t val);

uint8_t io_read8(uint16_t port);
uint16_t io_read16(uint16_t port);
uint32_t io_read32(uint16_t port);

void io_wrmsr(uint32_t msr, uint64_t val);
uint64_t io_rdmsr(uint32_t msr);